/*
 * @(#)Controller.java
 *
 * Revision:
 * Author                                         Date           
 * --------------------------------------------   ------------   
 *  Jeremias D. Serafim de Araujo                     14/11/2012    
 */

package br.edu.ufcg.splab.util;


import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import br.edu.ufcg.splab.core.InterfaceGenerate;
import br.edu.ufcg.splab.core.InterfaceGraph;
import br.edu.ufcg.splab.core.edges.EdgeType;
import br.edu.ufcg.splab.core.graph.Tree;
import br.edu.ufcg.splab.exceptions.LTSBTException;
import br.edu.ufcg.splab.exceptions.ParseException;
import br.edu.ufcg.splab.generator.ConvertGraphToTree;
import br.edu.ufcg.splab.generator.TestCase;
import br.edu.ufcg.splab.generator.TestCaseGenerator;
import br.edu.ufcg.splab.generator.TestSuite;
import br.edu.ufcg.splab.io.TestLinkXMLPreAndPostConditionWriter;
import br.edu.ufcg.splab.io.TestSuiteXMLParser;
import br.edu.ufcg.splab.parser.CompareParsers;
import br.edu.ufcg.splab.simulator.LTSSimulator;
import br.edu.ufcg.splab.techniques.Similarity;
import br.edu.ufcg.splab.techniques.reduction.functions.choice.LengthTestCases;
import br.edu.ufcg.splab.techniques.reduction.functions.similarity.SimilarityFunction;
import br.edu.ufcg.splab.techniques.reduction.requirement.RequirementTracer;
import br.edu.ufcg.splab.techniques.reduction.requirement.TransitionPairsTracerGenerator;
import br.edu.ufcg.splab.techniques.reduction.requirement.TransitionsTracerGenerator;
import br.edu.ufcg.splab.techniques.reduction.strategies.ReductionSimilarity;
import br.edu.ufcg.splab.techniques.regression.SART;

/**
 * 
 * @author Jeremias
 * 
 * TODO: The generation must be refactored. The IO should be transfered to one place (I suggest the Facade, or a different method).
 * All methods now are copy/paste from each other, hindering reuse, and understanding of methods. 
 *
 */

public class Controller {


	private InterfaceGraph readTgf(String fileName) throws FileNotFoundException, LTSBTException{
		ReadTGF read = new ReadTGF();
		InterfaceGraph graph = read.getGraph(fileName);
		return graph;
	}

	//caso exista outros geradores
	private InterfaceGenerate getGenerator(String model){
		InterfaceGenerate generator = null;
		if(model.toLowerCase().equals("lts")){
			generator = new TestCaseGenerator();//aqui tah com funcao de gerar e coletar os caminhos
		}if(model.toLowerCase().equals("tree")){
			generator = new TestCaseGenerator();//aqui tah com funcao de coletar caminhos
		}
		return generator;
	}
	
	public TestSuite generateFromGraph(String fileInputName,String fileOutputName) throws FileNotFoundException, LTSBTException{
		InterfaceGraph graph = readTgf(fileInputName);
		InterfaceGenerate generator = getGenerator("lts");
		TestSuite testSuite = generator.generate(graph);
		write(testSuite,fileOutputName);
		return testSuite;
		
	}
	
	public TestSuite generateFromTree(String fileInputName, int numOfExpansion,String fileOutputName) throws FileNotFoundException, LTSBTException{
		InterfaceGraph graph = readTgf(fileInputName);
		InterfaceGenerate generator = getGenerator("tree");
		ConvertGraphToTree convertsGraphToTree = new ConvertGraphToTree();
		Tree tree = convertsGraphToTree.converterGraph(graph);
		tree.expand(numOfExpansion);
		TestSuite testSuite = generator.generate(tree);
		write(testSuite,fileOutputName);
		return testSuite;
	}
	
	public TestSuite generateAnnotatedGraphFromGraph(String fileInputName,String fileOutputName) throws FileNotFoundException, LTSBTException{
		InterfaceGraph graph = readTgf(fileInputName);
		//GraphToAnnotatedGraphParser convertsAnnotatedGraph = new GraphToAnnotatedGraphParser();
		//InterfaceGraph newGraph = convertsAnnotatedGraph.graphContraction(graph);
		
		CompareParsers convertsAnnotatedGraph = new CompareParsers();
		InterfaceGraph newGraph = convertsAnnotatedGraph.compareGraphContraction(graph);
		
		InterfaceGenerate generator = getGenerator("lts");
		TestSuite testSuite = generator.generate(newGraph);
		write(testSuite,fileOutputName);
		return testSuite;
		
	}
	
	public TestSuite generateAnnotatedGraphFromTree(String fileInputName, int numOfExpansion, String fileOutputName) throws FileNotFoundException, LTSBTException{		
		InterfaceGraph graph = readTgf(fileInputName);
		//GraphToAnnotatedGraphParser convertsAnnotatedGraphToTree = new GraphToAnnotatedGraphParser();
		//InterfaceGraph newGraph = convertsAnnotatedGraphToTree.graphContraction(graph);
		
		CompareParsers convertsAnnotatedGraph = new CompareParsers();
		InterfaceGraph newGraph = convertsAnnotatedGraph.compareGraphContraction(graph);
		
		
		ConvertGraphToTree convertsGraphToTree = new ConvertGraphToTree();
		Tree tree = convertsGraphToTree.converterGraph(newGraph);
		tree.expand(numOfExpansion);		
		
		InterfaceGenerate generator = getGenerator("tree");		
		TestSuite testSuite = generator.generate(tree);
	
		write(testSuite,fileOutputName);		
		return testSuite;		
	}
	
	public TestSuite generateAnnotatedGraphFromGraphTestLink(String fileInputName,String fileOutputName) throws FileNotFoundException, LTSBTException{
		InterfaceGraph graph = readTgf(fileInputName);
		//GraphToAnnotatedGraphParser convertsAnnotatedGraph = new GraphToAnnotatedGraphParser();
		//InterfaceGraph newGraph = convertsAnnotatedGraph.graphContraction(graph);
		CompareParsers convertsAnnotatedGraph = new CompareParsers();
		InterfaceGraph newGraph = convertsAnnotatedGraph.compareGraphContraction(graph);
		
		InterfaceGenerate generator = getGenerator("lts");
		TestSuite testSuite = generator.generate(newGraph);
		MapTestSuite mapTS = new MapTestSuite(testSuite);
		TestSuite validTestSuite = this.getValidTS(testSuite);
		new TestLinkXMLPreAndPostConditionWriter().write(testSuite,fileOutputName, mapTS);
		new TestLinkXMLPreAndPostConditionWriter().write(validTestSuite,fileInputName.substring(0,fileInputName.length() - 4) + "_validTS.xml",mapTS);		
		return testSuite;		
	}
	
	public TestSuite generateAnnotatedGraphFromTreeTestLink(String fileInputName, int numOfExpansion, String fileOutputName) throws FileNotFoundException, LTSBTException{		
		InterfaceGraph graph = readTgf(fileInputName);
		//GraphToAnnotatedGraphParser convertsAnnotatedGraphToTree = new GraphToAnnotatedGraphParser();
		//InterfaceGraph newGraph = convertsAnnotatedGraphToTree.graphContraction(graph);
		
		CompareParsers convertsAnnotatedGraph = new CompareParsers();
		InterfaceGraph newGraph = convertsAnnotatedGraph.compareGraphContraction(graph);
		
		ConvertGraphToTree convertsGraphToTree = new ConvertGraphToTree();
		Tree tree = convertsGraphToTree.converterGraph(newGraph);
		tree.expand(numOfExpansion);		
		
		InterfaceGenerate generator = getGenerator("tree");		
		TestSuite testSuite = generator.generate(tree);
		TestSuite validTestSuite = this.getValidTS(testSuite);
		MapTestSuite mapTS = new MapTestSuite(testSuite);
		new TestLinkXMLPreAndPostConditionWriter().write(testSuite,fileOutputName,mapTS);
		new TestLinkXMLPreAndPostConditionWriter().write(validTestSuite,fileInputName.substring(0,fileInputName.length() - 4) + "_validTS.xml",mapTS);		
		return testSuite;		
	}
	
	public void startSimilarity(String testSuiteFileName, double percent, String fileOutputName) throws ParseException, IOException {
		Similarity similarity = new Similarity();
		TestSuite testSuite = read(testSuiteFileName);
		TestSuite test = similarity.executeSimilarity(testSuite, percent);
		write(test, fileOutputName);

	}
	
	private TestSuite read(String testSuiteFileName) throws ParseException, IOException{
		TestSuiteXMLParser parser = new TestSuiteXMLParser();	
		return parser.read(testSuiteFileName);
	}

	private void write(TestSuite testSuite, String fileOutputName){
		TestSuiteXMLParser parser = new TestSuiteXMLParser();
		parser.write(testSuite, fileOutputName);
	}
	
	/**
	 * Method responsible for creating the files with format
	 *  {@link https://sites.google.com/a/computacao.ufcg.edu.br/lts-bt/inputs tgf} in the directory of entry. 
	 * 
	 * @param graphs
	 * 			The list of graphs generated
	 * @param directorio
	 * 			The path to put the files tgf
	 */
	public  void GenerateFilesTGF(List<InterfaceGraph> graphs,String directorio){
		try {
		WriterToTGF writer = new WriterToTGF();
		for (int i = 0; i < graphs.size(); i++) {
			String filePath = directorio;
			writer.getTGFfromGraph(graphs.get(i), new File( filePath + "generated_" + i +".tgf"));
			}}
		catch (IOException e) {
				
				e.printStackTrace();
			}
		}
	/**
	 * Method responsible for saving the logs of the graphs,like this:
	 * <br>loop: 3->2 fail
	 * <br>loop: 7->5
	 * <br>fork: 5
	 * <br>join: 12 and 2
	 * 
	 * 
	 * @param buffers
	 * 			Graph logs to be written to the file
	 * @param directorio
	 * 			The path to put the file
	 * @throws IOException
	 * 			Throws IOException if an error occurs in the writing process.
	 */
	private String GenerateLog(List<StringBuffer> buffers,String directorio) throws IOException {
		BufferedWriter writer = new BufferedWriter(new FileWriter((directorio+"Logs"+".txt")));
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i <buffers.size(); i++) {
			writer.write("Graph" + i +":" );
			sb.append("Graph" + i +":");
			sb.append(System.getProperty("line.separator"));
			writer.newLine();
			writer.newLine();
			writer.write(buffers.get(i).toString());
			sb.append(buffers.get(i).toString());
			writer.newLine();
		}	
		writer.close();
		return sb.toString();
	}
	
	/**
	 * Method responsible for call the method {@link br.edu.ufcg.splab.simulator.LTSSimulator#getSimulatedLTS getSimulatedLTS} of the class LTSSimulator to generate the set of graphs.
	 * 
	 * @param depth
	 *            The maximum depth of the generated LTS,in other words,the biggest level between the root and the final state.
	 * @param quantity
	 *            The number of generated LTSs.
	 * @param nLoops
	 *            Quantity of  {@link br.edu.ufcg.splab.simulator.StructuralPattern#loop loops} to be inserted in the LTSs.           
	 * @param nJoins
	 *            Quantity of  {@link br.edu.ufcg.splab.simulator.StructuralPattern#join joins} to be inserted in the LTSs.
	 * @param nForks
	 *            Quantity of  {@link br.edu.ufcg.splab.simulator.StructuralPattern#fork forks} to be inserted in the LTSs.
	 * @param directorio
	 * 			The path to put the files
	 * @throws LTSBTException 
	 * @throws IOException 
	 *			
	 */
	
	public String generateGraphs(int depth, int quantity, int nLoops,int nJoins, int nForks,String directorio) throws LTSBTException, IOException{
		LTSSimulator sim = new LTSSimulator();
		List<InterfaceGraph> graphs = sim.getSimulatedLTS(depth, quantity, nLoops, nJoins, nForks);
		GenerateFilesTGF(graphs,directorio);
		String log = GenerateLog(sim.getBuffers(),directorio);	
		return log;
	}

	/**
	 * Selects Test Cases for WSA-RT using an annotated graph.
	 * @param baselineFile The file (tgf) with a baseline specification model.
	 * @param deltaFile The file (tgf) with a delta specification model.
	 * @param numOfExpansion The number of expansions in the tree for generation with loop coverage.
	 * @param outputFilename The output filename.
	 * @throws Exception
	 */
	public void selectSART(String baselineFile, String deltaFile, String outputFilename) throws Exception{
		
		//Baseline Test Suite and Models
		InterfaceGenerate generator = getGenerator("lts");		
		
		InterfaceGraph graphBaseline = readTgf(baselineFile);
		InterfaceGraph graphDelta = readTgf(deltaFile);
		
		TestSuite baselineTS = generator.generate(graphBaseline);
		TestSuite deltaTS = generator.generate(graphDelta);
		SART sart = new SART();
		TestSuite subset = sart.reduce(baselineTS, deltaTS);
		
		//TODO should be a return not a writer here. Redesign!
		new TestLinkXMLPreAndPostConditionWriter().write(subset,outputFilename);
	}
	
	/**
	 * Reduces test suite using reduction algorithm based on similarity. 
	 * It uses as default the old LTS generation algorithm.
	 *  
	 * @param fileInputName The file (tgf) with a specification model (LTS model).
	 * @param fileOutputName The output filename. 
	 * @return The test suite reduced.
	 * @throws Exception
	 */
	public TestSuite reduceSimFromGraphToGraph(String fileInputName, String fileOutputName, String type) throws Exception{
		InterfaceGraph graph = readTgf(fileInputName);
		InterfaceGenerate generator = getGenerator("lts");
		TestSuite testSuite = generator.generate(graph);
		
		List<RequirementTracer> tracers = new ArrayList<RequirementTracer>();
		if(type.equals("T")){
			TransitionsTracerGenerator transitions = new TransitionsTracerGenerator();
			RequirementTracer tracer = transitions.getTracer(testSuite);
			tracers.add(tracer);
		}else if(type.equals("P")){
			TransitionPairsTracerGenerator pairs = new TransitionPairsTracerGenerator();
			RequirementTracer tracer = pairs.getTracer(testSuite);
			tracers.add(tracer);
		}else if(type.equals("B")){
			TransitionsTracerGenerator transitions = new TransitionsTracerGenerator();
			RequirementTracer tracer1 = transitions.getTracer(testSuite);
			tracers.add(tracer1);
			TransitionPairsTracerGenerator pairs = new TransitionPairsTracerGenerator();
			RequirementTracer tracer2 = pairs.getTracer(testSuite);
			tracers.add(tracer2);			
		}
		
		SimilarityFunction function = new SimilarityFunction();
		LengthTestCases choice = new LengthTestCases();
		ReductionSimilarity sim =  new ReductionSimilarity(function, choice);
			
		TestSuite testSuiteReduced = sim.reduceTestSuite(testSuite, tracers);		
		//write(testSuiteReduced,fileOutputName);
		MapTestSuite mapTS = new MapTestSuite(testSuite);
		new TestLinkXMLPreAndPostConditionWriter().write(testSuite,fileInputName.substring(0,fileInputName.length() - 4) + "_generatedTS.xml",mapTS);
		new TestLinkXMLPreAndPostConditionWriter().write(testSuiteReduced,fileOutputName,mapTS);		
		
		
		return testSuiteReduced;
	}
	
	/**
	 * Reduces test suite using reduction algorithm based on similarity. 
	 * It used as input an simple LTS. It uses parameterized LTS as generation algorithm.
	 *  
	 * @param fileInputName The file (tgf) with a specification model (LTS model).
	 * @param numOfExpansion The number of expansions in the tree for generation with loop coverage.
	 * @param fileOutputName The output filename. 
	 * @return The test suite reduced.
	 * @throws Exception
	 */
	public TestSuite reduceSimFromGraphToTree(String fileInputName, int numOfExpansion, String fileOutputName, String type) throws Exception{
		InterfaceGraph graph = readTgf(fileInputName);
		InterfaceGenerate generator = getGenerator("tree");
		ConvertGraphToTree convertsGraphToTree = new ConvertGraphToTree();
		Tree tree = convertsGraphToTree.converterGraph(graph);
		tree.expand(numOfExpansion);
		TestSuite testSuite = generator.generate(tree);
	
		List<RequirementTracer> tracers = new ArrayList<RequirementTracer>();
		if(type.equals("T")){
			TransitionsTracerGenerator transitions = new TransitionsTracerGenerator();
			RequirementTracer tracer = transitions.getTracer(testSuite);
			tracers.add(tracer);
		}else if(type.equals("P")){
			TransitionPairsTracerGenerator pairs = new TransitionPairsTracerGenerator();
			RequirementTracer tracer = pairs.getTracer(testSuite);
			tracers.add(tracer);
		}else if(type.equals("B")){
			TransitionsTracerGenerator transitions = new TransitionsTracerGenerator();
			RequirementTracer tracer1 = transitions.getTracer(testSuite);
			tracers.add(tracer1);
			TransitionPairsTracerGenerator pairs = new TransitionPairsTracerGenerator();
			RequirementTracer tracer2 = pairs.getTracer(testSuite);
			tracers.add(tracer2);			
		}
		
		SimilarityFunction function = new SimilarityFunction();		
		LengthTestCases choice = new LengthTestCases();
		ReductionSimilarity sim =  new ReductionSimilarity(function, choice);
		
		TestSuite testSuiteReduced = sim.reduceTestSuite(testSuite, tracers);		
		//write(testSuiteReduced,fileOutputName);
		MapTestSuite mapTS = new MapTestSuite(testSuite);
		new TestLinkXMLPreAndPostConditionWriter().write(testSuite,fileInputName.substring(0,fileInputName.length() - 4) + "_generatedTS.xml",mapTS);
		new TestLinkXMLPreAndPostConditionWriter().write(testSuiteReduced,fileOutputName,mapTS);		
		
		return testSuiteReduced;
	}
	
	/**
	 * Reduces test suite using reduction algorithm based on similarity. 
	 * It used as input an annotated graph. 
	 * It uses as default the old LTS generation algorithm.
	 * 
	 * @param fileInputName The file (tgf) with a specification model (LTS model).
	 * @param fileOutputName The output filename. 
	 * @return The test suite reduced.
	 * @throws Exception
	 */
	public TestSuite reduceSimFromAnnotatedGraphToGraphTestLink(String fileInputName, String fileOutputName, String type) throws Exception{
		InterfaceGraph graph = readTgf(fileInputName);			
		//GraphToAnnotatedGraphParser parser = new GraphToAnnotatedGraphParser();
		//InterfaceGraph annotatedGraph = parser.graphContraction(graph);
		CompareParsers convertsAnnotatedGraph = new CompareParsers();
		InterfaceGraph annotatedGraph = convertsAnnotatedGraph.compareGraphContraction(graph);
		
		InterfaceGenerate generator = getGenerator("lts");		
		TestSuite testSuite = generator.generate(annotatedGraph);	
		MapTestSuite mapTS = new MapTestSuite(testSuite);
		TestSuite validTestSuite = this.getValidTS(testSuite);

		List<RequirementTracer> tracers = new ArrayList<RequirementTracer>();
		if(type.equals("T")){
			TransitionsTracerGenerator transitions = new TransitionsTracerGenerator();
			RequirementTracer tracer = transitions.getTracer(testSuite);
			tracers.add(tracer);
		}else if(type.equals("P")){
			TransitionPairsTracerGenerator pairs = new TransitionPairsTracerGenerator();
			RequirementTracer tracer = pairs.getTracer(testSuite);
			tracers.add(tracer);
		}else if(type.equals("B")){
			TransitionsTracerGenerator transitions = new TransitionsTracerGenerator();
			RequirementTracer tracer1 = transitions.getTracer(testSuite);
			tracers.add(tracer1);
			TransitionPairsTracerGenerator pairs = new TransitionPairsTracerGenerator();
			RequirementTracer tracer2 = pairs.getTracer(testSuite);
			tracers.add(tracer2);			
		}
		
		SimilarityFunction function = new SimilarityFunction();		
		LengthTestCases choice = new LengthTestCases();
		ReductionSimilarity sim =  new ReductionSimilarity(function, choice);
		TestSuite testSuiteReduced = sim.reduceTestSuite(validTestSuite, tracers);	
		
		new TestLinkXMLPreAndPostConditionWriter().write(testSuite,fileInputName.substring(0,fileInputName.length() - 4) + "_generatedTS.xml",mapTS);
		new TestLinkXMLPreAndPostConditionWriter().write(validTestSuite,fileInputName.substring(0,fileInputName.length() - 4) + "_validTS.xml",mapTS);		
		new TestLinkXMLPreAndPostConditionWriter().write(testSuiteReduced,fileOutputName,mapTS);
		
		return testSuiteReduced;
	}
	
	/**
	 * Reduces test suite using reduction algorithm based on similarity. 
	 * It used as input an annotated graph.
	 * It uses parameterized LTS as generation algorithm.
	 * 
	 * @param fileInputName The file (tgf) with a specification model (LTS model).
	 * @param numOfExpansion The number of expansions in the tree for generation with loop coverage.
	 * @param fileOutputName The output filename.
	 * @return The test suite reduced.
	 * @throws Exception
	 */
	public TestSuite reduceSimFromAnnotatedGraphToTreeTestLink(String fileInputName, int numOfExpansion, String fileOutputName, String type) throws Exception{
		InterfaceGraph graph = readTgf(fileInputName);			

		TestSuite testSuite = treeGenerationFromAnnotatedGraph(graph, numOfExpansion);
		
		MapTestSuite mapTS = new MapTestSuite(testSuite);
		TestSuite validTestSuite = this.getValidTS(testSuite);

		List<RequirementTracer> tracers = new ArrayList<RequirementTracer>();
		if(type.equals("T")){
			TransitionsTracerGenerator transitions = new TransitionsTracerGenerator();
			RequirementTracer tracer = transitions.getTracer(testSuite);
			tracers.add(tracer);
		}else if(type.equals("P")){
			TransitionPairsTracerGenerator pairs = new TransitionPairsTracerGenerator();
			RequirementTracer tracer = pairs.getTracer(testSuite);
			tracers.add(tracer);
		}else if(type.equals("B")){
			TransitionsTracerGenerator transitions = new TransitionsTracerGenerator();
			RequirementTracer tracer1 = transitions.getTracer(testSuite);
			tracers.add(tracer1);
			TransitionPairsTracerGenerator pairs = new TransitionPairsTracerGenerator();
			RequirementTracer tracer2 = pairs.getTracer(testSuite);
			tracers.add(tracer2);			
		}
		
		SimilarityFunction function = new SimilarityFunction();		
		LengthTestCases choice = new LengthTestCases();
		ReductionSimilarity sim =  new ReductionSimilarity(function, choice);
		
		TestSuite testSuiteReduced = sim.reduceTestSuite(validTestSuite, tracers);	
		
		new TestLinkXMLPreAndPostConditionWriter().write(testSuite,fileInputName.substring(0,fileInputName.length() - 4) + "_generatedTS.xml",mapTS);
		new TestLinkXMLPreAndPostConditionWriter().write(validTestSuite,fileInputName.substring(0,fileInputName.length() - 4) + "_validTS.xml",mapTS);
		new TestLinkXMLPreAndPostConditionWriter().write(testSuiteReduced,fileOutputName,mapTS);
		
		return testSuiteReduced;
	}
	
	//TODO: Added by Neto to refactor generation.
	public TestSuite treeGenerationFromAnnotatedGraph(InterfaceGraph graph, int numOfExpansion) throws FileNotFoundException, LTSBTException{		
		//GraphToAnnotatedGraphParser convertsAnnotatedGraphToTree = new GraphToAnnotatedGraphParser();
		//InterfaceGraph newGraph = convertsAnnotatedGraphToTree.graphContraction(graph);
		//TODO: added by Ana Emilia to compare the two conversions of graph to annotated graph.
		CompareParsers convertsAnnotatedGraph = new CompareParsers();
		InterfaceGraph newGraph = convertsAnnotatedGraph.compareGraphContraction(graph);
		
		ConvertGraphToTree convertsGraphToTree = new ConvertGraphToTree();
		Tree tree = convertsGraphToTree.converterGraph(newGraph);
		tree.expand(numOfExpansion);		
		
		InterfaceGenerate generator = getGenerator("tree");		
		TestSuite testSuite = generator.generate(tree);	
		return testSuite;		
	}

	//Added by Neto to remove test cases ending with a "steps" type of edge.
	public TestSuite getValidTS(TestSuite ts){
		TestSuite validTS = new TestSuite();
		for(TestCase tc : ts){
			//if test case ends with an expected results, or ends with a conditions (post-condition) after a last expected result.
//			if((tc.get(tc.size()-1).getType().equals(EdgeType.EXPECTED_RESULTS)) ||
//			   ((tc.get(tc.size()-2).getType().equals(EdgeType.EXPECTED_RESULTS) && (tc.get(tc.size()-1).getType().equals(EdgeType.CONDITIONS))))){
//				validTS.add(tc);
//			}
			//TODO: conforme o sugerido pela professora
			//Patricia: "Acho que podemos adotar a regra mais geral de nao permitir que um step encerre."
			if((!tc.get(tc.size()-1).getType().equals(EdgeType.STEPS))){
				validTS.add(tc);
			}
		}
		return validTS;
	}

}